const nodemailer = require('nodemailer');

// 创建一个 nodemailer transporter
const transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'youremail@gmail.com',
        pass: 'yourpassword'
    }
});

// 发送邮件的函数
const sendEmail = async (to, subject, text) => {
    // 设置邮件内容
    const mailOptions = {
        from: 'youremail@gmail.com',
        to: to,
        subject: subject,
        text: text
    };

    // 发送邮件
    transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
            console.log(error);
        } else {
            console.log('Email sent: ' + info.response);
        }
    });
};

module.exports = {
    sendEmail
};
